package cn.edu.nankai.bookstore.controller.receiver;

import cn.edu.nankai.bookstore.domain.po.Receiver;
import cn.edu.nankai.bookstore.service.OrderService;
import cn.edu.nankai.bookstore.service.ReceiverService;
import cn.edu.nankai.bookstore.service.impl.OrderServiceImpl;
import cn.edu.nankai.bookstore.service.impl.ReceiverServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "AddReceiverServlet", value = "/AddReceiverServlet")
public class AddReceiverServlet extends HttpServlet {
    private ReceiverService receiverService = new ReceiverServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        if(session.getAttribute("su") == null){
            response.getWriter().write("{access:'deny'}");
            return;
        }
        String name = (String) request.getParameter("name");
        Boolean status = receiverService.registerReceiver(new Receiver(name));
        response.getWriter().write(status.toString());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
